﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>易买网 - 首页</title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
<script type="text/javascript" src="scripts/function.js"></script>
</head>
<body>
<%@include file="nav.jsp"%>
<div id="register" class="wrap">
	<div class="shadow">
		<em class="corner lb"></em>
		<em class="corner rt"></em>
		<div class="box">
			<h1>欢迎回到易买网</h1>
			<form id="loginForm" method="post" action="login" onsubmit="return checkLogin()">
				<table>
					<tr>
						<td class="field">用户名：</td>
						<td><input class="text" type="text" name="userName" onfocus="FocusItem(this)" onblur="CheckItem(this);" /><span></span></td>
					</tr>
					<tr>
						<td class="field">登录密码：</td>
						<td><input class="text" type="password" id="passWord" name="password" onfocus="FocusItem(this)" onblur="CheckItem(this);" /><span></span></td>
					</tr>
					<%--	验证码问题				--%>
					<tr>
						<td class="field">验证码：</td>
						<td>
							<input class="text" type="text" id="code" name="code"
								   onblur="checkCode()" />
						</td>
					</tr>
					<tr>
						<td></td>
						<td >
							<img id="img" src="code.jsp" align="absmiddle"/>
							<a href="javascript:change()">看不清</a>
						</td>
					</tr>


					<tr>
						<td></td>
						<td><label class="ui-green"><input type="submit" name="submit" value="立即登录" /></label></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	<div class="clear"></div>
</div>
<div id="footer">
	Copyright &copy; 2022 卓京教育 All Rights Reserved. 湘ICP证1001号
</div>
</body>
</html>
<script type="text/javascript">
	function change(){
		//alert("change()");
		document.getElementById("img").src="code.jsp?"+Math.random();
	}

	var isFlag = false;
	function checkLogin() {
		return isFlag;
	}


	function checkCode(){
		var code = document.getElementById("code").value;
		//alert(code);
		doAjax("checkCodeServlet?code=" + code);
	}

	var xmlhttp;
	function doAjax(url){
		//第1步:获得ajaxRequest请求对象,解决浏览器的兼容问题
		if(window.XMLHttpRequest){
			xmlhttp = new XMLHttpRequest();
		}else{
			var names=["msxml","msxml2","msxml3","Microsoft"];
			for(vari=0;i<names.length;i++){
				try{
					var name=names[i]+".XMLHTTP";
					xmlhttp = new ActiveXObject(name);
				}catch(e){
					throw 'get request error';
				}
			}
		}

		//alert(url);
		//第2步:打开请求     让ajaxRequest做什么事
		xmlhttp.open("post", url, true);
		//如果以post方式请求，必须要添加设置头部信息
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		//发送请求
		xmlhttp.send(null);

		//第3步:编写ajaxRequest做完事后的回调函数
		xmlhttp.onreadystatechange = processRequest;
	}

	function processRequest() {
		// var username = document.getElementById("username");
		if (xmlhttp.readyState == 4){
			//alert("xmlhttp.status=="+xmlhttp.status);
			if (xmlhttp.status == 200) {
				//responseText表示请求完成后，返回的字符串信息
				//alert(xmlhttp.responseText);
				if (xmlhttp.responseText == "false"){
					alert("验证码错误");
					isFlag = false;
				}else {
					// alert("验证码正确");
					isFlag = true;
				}
			} else {
				alert("请求处理返回的数据有错误");
			}
		}
	}


</script>